package it.tutorial.jmx.management;

import it.tutorial.jmx.mbeans.Prova;
import it.tutorial.jmx.mbeans.ProvaMBean;

import java.lang.management.ManagementFactory;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

public class ProvaManagement {
	
	private static final int VAR1 = 1;
	private static final String VAR2 = "prova";
	
	public static void main(String[] args) throws MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, InterruptedException {
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		
		Prova myMBean = new Prova(VAR1,VAR2);

		ObjectName name = new ObjectName("it.tutorial.jmx.mbeans:type=Prova");
		mbs.registerMBean(myMBean, name);
		 
		do{
            Thread.sleep(2000);
            System.out.println("Var1="+myMBean.getVar1());
        }while(myMBean.getVar1() !=-1);
		
	}

}
